<?php 

$keyword = "";
$listaRecepta = "";
$isAdmin = isAdmin();

$pretragaForm = "
	<div class='content' style=\"width: 300px\">
		<form method='POST' action='recepti.php?action=pretraga'>
			<table><tr>
			<td> <input type='text' name='pretraga' placeholder='Upišite riječ pretrage..'></td>
			<td> <input type='submit' value='Pretraži' ></td>
			</tr></table>
		</form>
	</div><br>";

if (isset($_GET['action'])) {
	if (strcmp($_GET['action'],"pretraga") == 0 ) {
		$_POST['pretraga'] = "";
	}
}

if (isset($_POST['pretraga'])) {
	$keyword = $_POST['pretraga'];

	$query = "SELECT * FROM recepti WHERE 
		naziv LIKE '%" . $keyword . "%' OR 
		opis LIKE '%" . $keyword . "%' OR 
		reference LIKE '%" . $keyword . "%' OR 
		vlasnik LIKE '%" . $keyword . "%';";
	
	$result = myQuery($query);
	
	$listaRecepta .= "
		<div class='content'>
			<span class='contentTitle'> Lista recepta </span>
			<table class='tableResult' cellspacing='0' width='100%'><tr>
			<th scope='col' width='150px'> Naziv </td> 
			<th scope='col' width='400px'> Opis </td>
			<th scope='col' width='250px'> Reference </td> 
			<th scope='col' width='150px'> Vlasnik </td>";
	
	
	while ($row = mysql_fetch_array($result)) {
		$listaRecepta .= "<tr align=\"center\">
				<td> " . $row['naziv'] . "</td>
				<td> " . $row['opis'] . "</td>
				<td> " . $row['reference'] . "</td>
				<td> " . $row['vlasnik'] . "</td>";
		if ($isAdmin) $listaRecepta .= "
				<td width='16px'> <a title='Promijeni recept' href='recepti.php?action=edit&id=" . $row['id'] . "'> 
					<img src='/images/edit.png' width='16px' height='16px'> </a> </td>
				<td width='16px'> <a title='Pobriši recept' href='exec/recepti.php?action=delete&id=" . $row['id'] . "'> 
					<img src='/images/delete.png' width='16px' height='16px'> </td>";
		
		$listaRecepta .= "</tr>";
	}
	
	$listaRecepta .= "</table></div>";
}

print($pretragaForm);
print($listaRecepta);

?>
